﻿@using XStudio.XCRF.Web.Models.Member
@model MemberChangePasswordDTO
@{
    ViewBag.Title = "修改密码";
    Layout = "~/Views/Shared/Master.cshtml";
}
@{Html.Telerik().Window().Name("ChangePasswordSelfWindow").Title("修改密码").HtmlAttributes(new { @class = "ContentWindow" })
    .Buttons(buttons => buttons.Clear())
    .Content(
@<text>
@{using (Ajax.BeginForm<MemberController>(c => c._MemberChangePasswordSelf(null),
    new AjaxOptions { OnBegin = "BeforeSend", OnSuccess = "OnSuccess", OnFailure = "OnError" }))
  {
<table>
    <tr>
        <th>用户名</th>
        <td>@LoginSession.LoginName</td>
    </tr>
    <tr>
        <th>旧密码</th>
        <td>@Html.SecurePasswordFor(model => model.OldPasscode)</td>
    </tr>
    <tr>
        <th>新密码</th>
        <td>@Html.SecurePasswordFor(model => model.NewPasscode1)</td>
    </tr>
    <tr>
        <th>再次输入新密码</th>
        <td>@Html.SecurePasswordFor(model => Model.NewPasscode2)</td>
    </tr>
</table>
<input type="submit" id="btnChangePassword" value="提交" />
  }
}
</text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("saving").Title("系统提示")
    .Buttons(buttons => buttons.Clear())
    .ClientEvents(window => window.OnOpen("OnSavingOpen"))
    .Content(
@<text>
正在保存，请稍后...
</text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("saveError").Title("系统提示")
    .Buttons(buttons => buttons.Close())
    .ClientEvents(window => window.OnOpen("OnSaveErrorOpen").OnClose("OnSaveErrorClose"))
    .Content(
@<text>
出现错误，请重试！
</text>)
    .Render();
}
<script type="text/javascript">
    $("#btnChangePassword").click(function () {
        var txtOldPasscode = $("#OldPasscode");
        var txtNewPasscode1 = $("#NewPasscode1");
        var txtNewPasscode2 = $("#NewPasscode2");
        var oldPasscode = txtOldPasscode.val().Base64Encode();
        var newPasscode1 = txtNewPasscode1.val().Base64Encode();
        var newPasscode2 = txtNewPasscode2.val().Base64Encode();
        txtOldPasscode.val(oldPasscode);
        txtNewPasscode1.val(newPasscode1);
        txtNewPasscode2.val(newPasscode2);
    });
    function OnSavingOpen() {
        $("#saving").data("tWindow").center();
    }
    function OnSaveErrorOpen() {
        $("#saveError").data("tWindow").center();
    }
    function OnSaveErrorClose() {
        $("#OldPasscode").val("");
        $("#NewPasscode1").val("");
        $("#NewPasscode2").val("");
    }
    function BeforeSend() {
        $("#saving").data("tWindow").open();
    }
    function OnSuccess(data) {
        if (data.ID) {
            window.location = "@(Url.Action<MemberController>(c => c.MemberLogin()))";
        } else {
            $("#saveError").data("tWindow").open();
            $("#saving").data("tWindow").close();
        }
    }
    function OnError() {
        $("#saveError").data("tWindow").open();
        $("#saving").data("tWindow").close();
    }
</script>